package com.koron.system.staff.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.base.BaseQueryBean;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.dto.OutStaffApplyBean;
import com.koron.bean.system.staff.dto.OutStaffAuditBean;
import com.koron.bean.system.staff.dto.OutStaffBean;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.system.staff.service.OutStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.Pattern;

/**
 * @ClassName OutStaffController
 * @description
 * @Author zhouj
 * @Date 2021/7/7 16:35
 */
@Slf4j
@RequestMapping("/system/outStaff")
@RestController
@Api(tags = "外单位人员")
@Validated
public class OutStaffController {

    @Autowired
    OutStaffService outStaffService;

    @PostMapping("/insert")
    @ApiOperation(value = "外单位注册")
    public Response regist(@RequestBody OutStaffBean outStaffBean) {
        return outStaffService.regist(outStaffBean);
    }

    @PutMapping("/update")
    @ApiOperation(value = "外单位修改")
    public Response update(@RequestBody OutStaffBean outStaffBean) {
        return Response.success(outStaffService.update(outStaffBean));
    }

    @GetMapping("/sendPhoneMessage")
    @ApiOperation(value = "发送手机验证码")
    public Response sendPhoneMessage(@RequestParam @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")  String phone) {
        return Response.success(outStaffService.sendPhoneMessage(phone));
    }

    @GetMapping("/queryAuditList")
    @ApiOperation(value = "外单位审核列表")
    public Response queryAuditList(OutStaffApplyBean applyBean, BaseQueryBean queryBean) {
        PageHelper.startPage(queryBean.getPage(), queryBean.getPageSize());
        return Response.success(new PageInfo(outStaffService.queryAuditList(applyBean, queryBean)));
    }

    @PutMapping("/audit")
    @ApiOperation(value = "外单位审核 同意 拒绝")
    public Response audit(@CasUser @ApiIgnore EamUser user, @RequestBody OutStaffAuditBean outStaffAuditBean) {
        return Response.success(outStaffService.audit(user, outStaffAuditBean));
    }

}
